package level4.shaders
{
	import flash.display.DisplayObject;
	import flash.display.Shader;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	
	import level4.engines.GameEngine;
	import level4.interfaces.IGameComponent;

	/**
	 * 母shader
	 * */
	public class BaseShader implements IGameComponent
	{
		protected var do2d:DisplayObject;
		
		protected var shader:Shader;
		
		protected var isShaderLoadOk:Boolean;
		
		public function BaseShader(url:String,do2d:DisplayObject)
		{
			this.do2d = do2d;
			var l:URLLoader = new URLLoader(new URLRequest(url));
				l.dataFormat = URLLoaderDataFormat.BINARY;
				l.addEventListener(Event.COMPLETE,shaderLoadOk);
		}
		
		protected function shaderLoadOk(e:Event):void{
			e.target.removeEventListener(Event.COMPLETE,shaderLoadOk);
			shader = new Shader(e.target.data);
			isShaderLoadOk = true;
			GameEngine.addComponent(this);
		}
		
		public function update(timeDiff:Number):void{}
		
		public function clean():void{
			GameEngine.removeComponent(this);
			do2d.filters = [];
			do2d = null;
		}
	}
}